package com.ft.admix.bd.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mobads.sdk.api.ExpressResponse;
import com.ft.adbix.utils.universalimageloader.core.ImageLoader;
import com.kwad.sdk.api.KsAdVideoPlayConfig;
import com.kwad.sdk.api.KsImage;
import com.kwad.sdk.api.KsNativeAd;
import com.ft.admix.ad.MixCustomNativeAd;
import com.kwad.sdk.api.model.AdSourceLogoType;
import com.kwad.sdk.api.model.InteractionType;
import com.kwad.sdk.api.model.KsNativeConvertType;
import com.kwad.sdk.api.model.MaterialType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CustomBDExpressNativeAd extends MixCustomNativeAd {
    ExpressResponse expressAd;
    Activity mActivity;

    public CustomBDExpressNativeAd(Activity activity, ExpressResponse expressAd) {
        this.expressAd = expressAd;
        this.mActivity = activity;
        bindExpressListeners();
    }

    @Override
    public void render(ViewGroup viewGroup) {
        super.render(viewGroup);
        // 快手原生广告的渲染
        if (expressAd != null) {
            expressAd.render();
            // 快手SDK的渲染方法可能不同，需要根据实际SDK文档调整
        }
    }

    private void bindExpressListeners() {
        // 注册监听
        expressAd.setInteractionListener(new ExpressResponse.ExpressInteractionListener() {
            @Override
            public void onAdClick() {
                callAdClick();
            }

            @Override
            public void onAdExposed() {
                callAdShow();
            }

            @Override
            public void onAdRenderFail(View adView, String reason, int code) {
                callRenderFail(adView, code, reason);
            }

            @Override
            public void onAdRenderSuccess(View adView, float width, float height) {
                callRenderSuccess(width, height);
            }

            @Override
            public void onAdUnionClick() {
                callAdClick();
            }
        });
        expressAd.setAdPrivacyListener(new ExpressResponse.ExpressAdDownloadWindowListener() {
            @Override
            public void onADPrivacyClick() {

            }

            @Override
            public void onADFunctionClick() {
            }

            @Override
            public void onADPermissionShow() {
            }

            @Override
            public void onADPermissionClose() {
            }

            @Override
            public void adDownloadWindowShow() {
            }

            @Override
            public void adDownloadWindowClose() {
            }
        });
        // 负反馈按钮&负反馈弹框的点击事件
        expressAd.setAdDislikeListener(new ExpressResponse.ExpressDislikeListener() {
            @Override
            public void onDislikeWindowShow() {
                callDislikeShow();
            }

            @Override
            public void onDislikeItemClick(String reason) {
                callDislikeSelected(0, reason);
            }

            @Override
            public void onDislikeWindowClose() {
                callDislikeCancel();
            }
        });
        // 广告位开启一键关闭功能后，需要注册此监听，处理点击负反馈后的关闭广告事件
        expressAd.setAdCloseListener(new ExpressResponse.ExpressCloseListener() {
            @Override
            public void onAdClose(ExpressResponse expressResponse) {
                // 移除被关闭的广告

            }
        });
    }

    @Override
    public View getExpressView(ViewGroup viewGroup) {
        return expressAd.getExpressAdView();
    }

} 